import request from '@/utils/request'
import request2 from '@/utils/request2'
import qs from 'qs'
import {
  processApiUrl
} from '../config'

/**
 * 待办事项列表
 * @param data 查询条件
 */
export function getTodoList(data) {
  return request({
    url: processApiUrl + '/cms/task/userTasks',
    method: 'post',
    data
  })
}



/**
 * 获取某流程实例的执行节点情况
 * @param data 查看参数
 */
export function getProcessNodeList(data) {

  return request.post(`${processApiUrl}/cms/process/procInstFinisedTask`, data)
}

/**
 * 获取某流程实例的当前执行节点情况
 * @param data 查看参数
 */

export function getCurrentProcess(data) {
  return request({
    url: `${processApiUrl}/cms/process/queryActiveProcTaskInfo/${data}`,
    method: 'get',

  })
}

/**
 * 获取正在进行中流程信息
 * @param data 查看参数
 */

export function queryActiveTaskInfo(data) {
  return request({
    url: `${processApiUrl}/cms/process/queryActiveTaskInfo/${data}`,
    method: 'get',

  })
}



/**
 * 获取当前流程的流程图
 * @param data 查看参数
 */

export function getFlowChart(data) {
  return request({
    url: `${processApiUrl}/cms/process/activeProcImage/${data}`,
    method: 'get',

  })
}
export function getFlowChart2(data) {
  return request2({
    url: `${processApiUrl}/cms/process/activeProcImage/${data}`,
    method: 'get',
  })
}
/**
 * 根据业务ID查询流程实例列表
 * @param data 查看参数
 */
export function getProcInstByBusiness(data) {
  return request({
    url: `${processApiUrl}/cms/process/procInstByBusiness`,
    method: 'get',
    params: data
  })
  // return request.get(`${processApiUrl}/cms/process/procInstByBusiness`,data:data)
}

/**
 * 节点任务处理
 * @param data
 */
export function completeTask(data) {
  return request.post(`${processApiUrl}/cms/task/completeTask`, data)
}

/**
 * 批量完成任务
 * @param data
 */
export function completeTaskBath(data) {
  return request.post(`${processApiUrl}/cms/task/completeTaskBath`, data)
}



/**
 * 待办事项统计
 */
export function getTodoTotal(data = {}) {
  return request({
    url: `${processApiUrl}/cms/task/taskTypeCount`,
    method: 'post',
    data
  })
}

/**
 * 已办事项统计
 */
export function getDoneTotal(data = {}) {
  return request({
    url: `${processApiUrl}/cms/task/hiTaskTypeCount`,
    method: 'post',
    data
  })
}
/**
 * @description: 获取意见征询列表
 * @param {object} data
 * @return {promise}
 */
export function getByProcInstId(data) {
  return request({
    url: `${processApiUrl}/approvalConsult/getByProcInstId/${data}`,
    method: 'get'
  })
}
/**
 * @description: 获取审批配置信息
 * @param {object} data
 * @return {promise}
 */
export function getConfig(data) {
  return request({
    url: `${processApiUrl}/cms/process/config`,
    method: 'get',
    params: data
  })
}
/**
 * @description: 获取下级审批人
 * @param {object} data
 * @return {promise}
 */
export function getNextAssign(data) {
  return request({
    url: `${processApiUrl}/assign/getNextAssign`,
    method: 'get',
    params: data
  })
}
/**
 * @description: 是否最后一个审批节点
 * @param {object} data
 * @return {promise}
 */
export function lastTask(data) {
  return request({
    url: `${processApiUrl}/assign/lastTask`,
    method: 'get',
    params: data
  })
}
/**
 * @description: 是否是转办
 * @param {object} data
 * @return {promise}
 */
export function tranfer(data) {
  return request({
    url: `${processApiUrl}/tranferRecord/task/tranfer`,
    method: 'get',
    params: data
  })
}
/**
 * @description: 意见征询保存
 * @param {object} data
 * @return {promise}
 */
export function save(data) {
  return request({
    url: `${processApiUrl}/approvalConsult/save`,
    method: 'post',
    data
  })
}
/**
 * @description: 转办
 * @param {object} data
 * @return {promise}
 */
export function tranferTask(data) {
  return request({
    url: `${processApiUrl}/tranferRecord/tranferTask`,
    method: 'post',
    data
  })
}
/**
 * @description: 转办退回
 * @param {object} data
 * @return {promise}
 */
export function tranferTaskRecall(data) {
  return request({
    url: `${processApiUrl}/tranferRecord/tranferTask_recall`,
    method: 'get',
    params: data
  })
}
/**
 * @description: 流程清除
 * @param {object} data
 * @return {promise}
 */
export function deleteProcess(data) {
  return request({
    url: `${processApiUrl}/tranferRecord/deleteProcess`,
    method: 'post',
    params: data,
    paramsSerializer: params => {
      return qs.stringify(params, { indices: false })
    }
  })
}
/**
 * @description: 获取审批信息
 * @param {object} data
 * @return {promise}
 */
export function processDetail(data) {
  return request({
    url: `${processApiUrl}/approvalConsult/processDetail`,
    method: 'get',
    params: data
  })
}
/**
 * @description: 退回至上一级
 * @param {object} data
 * @return {promise}
 */
export function recallPrevTask(data) {
  return request({
    url: `${processApiUrl}/tranferRecord/recallPrevTask`,
    method: 'get',
    params: data
  })
}
/**
 * @description: 获取征询信息
 * @param {object} data
 * @return {promise}
 */
export function getById(data) {
  return request({
    url: `${processApiUrl}/approvalConsult/getById?id=${data}`,
    method: 'get'
  })
}
/**
 * @description: 意见回复
 * @param {object} data
 * @return {promise}
 */
export function update(data) {
  return request({
    url: `${processApiUrl}/approvalConsult/update`,
    method: 'post',
    data
  })
}
/**
 * @description: 获取审批人
 * @param {object} data
 * @return {promise}
 */
export function getAdminAssign(data) {
  return request({
    url: `${processApiUrl}/assign/getAdminAssign`,
    method: 'get',
    params: data
  })
}

/**
 * @description: 批量审批查看数据是否被转办
 * @param {object} data
 * @return {promise}
 */
 export function tranferBath(data) {
  return request({
    url: `${processApiUrl}/tranferRecord/task/tranferBath`,
    method: 'post',
    data
  })
}
